<?php
$cs = Yii::app()->getClientScript();
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_find.css');
?>
<div data-role='page' id='demo-page'>
    <div data-role="header">
        <h1>比邻平台</h1>
    </div>
    <div data-role='content' id='mainContent' style="padding: 5px;">
        <?php
        $screen = Blyn::app()->getUIManager()->getCurrentScreen();
        $wxControl = $screen->getChildControl('BUIWXControl_1');
        $wxControl->renderView('booking_home', array());
        $cart = new BWCart();
        $view = $cart->getView(array('itemData' => array('paymentStatus' => bcart::Payment_Status_Paid)));
        ?>


        <legend>
            <strong><?php echo '我的预订记录'; ?></strong>|<small>
                <?php
                echo $wxControl->getLink(array(
                    'name' => '我的未支付订单',
                    'id' => 'showMyBookingList_1'), array(
                    'paymentStatus' => 'unpaid'));
                ?></small>
        </legend>

        <table data-role="table" id="table-custom-2" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-btn-theme="b" data-column-btn-text="显示列" data-column-popup-theme="a">
            <thead>
                <tr>
                    <th data-priority="3">
                        <input type="checkbox"  id="selectAll" data-role="none"  style="display:inline;"/>
                    </th> 
                    <th data-priority="3"><?php echo '序号'; ?></th>
                    <th data-priority="2"><?php echo '支付ID'; ?></th>
                    <th data-priority="1"><?php echo '产品名称'; ?></th>
                    <th data-priority="4"><?php echo '产品ID'; ?></th>
                    <th data-priority="1"><?php echo '金额（元）'; ?></th>
                    <th data-priority="1"><?php echo '付款时间'; ?></th>
                    <th data-priority="1">查看</th>
                </tr> 
            </thead>
            <fieldset>
                <tbody>
                    <?php
                    $totalMoney = 0;
                    $serial = 0;
                    $bookingTable = new BTreeTable('BWInputValue');
                    foreach ($view as $cartList) {
                        if ($cartList instanceof BTreeList) {
                            $serial++;
                            $cartId = $cartList->getId();
                            $price = $cartList->getItem('price')->value;
                            $unit = $cartList->getItem('moneyUnit')->value;
                            $quantity = $cartList->getItem('quantity')->value;
                            $productName = $cartList->getItem('productName')->value;
                            $productId = $cartList->getItem('productId')->value;
                            $paidMoney = $price * $quantity;
                            $paidTime = $cartList->getItem('paidTime')->value;
                            $paidTimeString = date('Ymd G:i:s', $paidTime);
                        }
                        ?>
                        <tr>

                            <td><label class="checkbox">
                                    <input type="checkbox" name="checkbox[]" value="<?php // echo $cartId;  ?>" data-role="none" style="display:inline;"/> 
                                </label></td>
                            <td> <?php echo $serial; ?> </td>
                            <td> <?php echo $cartId; ?> </td>
                            <td> <?php echo $productName; ?> </td>       
                            <td> <?php echo $productId; ?> </td>      
                            <td> <?php echo $paidMoney; ?> </td>   
                            <td> <?php echo $paidTimeString; ?> </td>   
                            <td>
                                <div class="row-fluid">                         
                                    <?php
                                        $bookingRow = $bookingTable->getListById($productId);
                                        $cancelTime = $bookingRow->getItem('bookingCancelTime')->value;
                                        echo $wxControl->getLink(array('name' => '订单详情', 'id' => 'showAddBookable_1'), array(
                                            'productId' => $productId,
                                            'ajaxContainerId' => 'myModal2',
                                            'htmlOptions' => array(
                                                'enctype' => 'multipart/form-data',
                                            ),
                                            'ajaxOptions' => array(
                                                'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal2").modal("show");}')
                                        ));
                                        if ($cancelTime > time()) {
                                            echo " | ";
                                            echo $wxControl->getLink(array('name' => '取消预订', 'id' => 'cancelPaidBooking_1'), array('cartId' => $cartId, 'bookingId' => $productId));
                                        }
                                        ?>
                                </div>                      
                            </td>
                        </tr>
                    <?php } ?>          
                </tbody>
            </fieldset>
        </table>

        <div id="myModal2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
        <div><input type="hidden" name="curPageNo" value="1"></div>

        <div data-role="controlgroup" data-type="horizontal" data-mini="true">
            <a href="javascript:void()" class="ui-btn ui-btn-corner-all">前一页</a>
            <a href="javascript:void()" class="ui-btn ui-btn-corner-all">1</a>
            <a href="javascript:void()" class="ui-btn ui-btn-corner-all">后一页</a>
        </div>
    </div>
    <div data-role="footer" data-position="fixed">
        <div data-role="navbar">
            <ul>
                <li><a href="#" id="find" data-icon="search">分类查询</a></li>
                <li><a href="#" id="mybooking" data-icon="shop" class="ui-btn-active">我的预订</a></li>
                <li><a href="#" data-icon="gear">其他</a></li>
            </ul>
        </div><!-- /navbar -->
    </div><!-- /footer -->